<template>
  <div id="sampleQuerysss">
    <el-card class="box-card" style="margin:15px">
      <el-form
        ref="basicForm"
        :rules="basicDataRules"
        :inline="true"
        :model="basicData.model"
        class="demo-form-inline"
        label-width="120px"
        size="small"
      >
        <el-row>
          <el-row>
            <el-col :span="6">
              <el-form-item label="所属区县:" prop="areaId.key">
                <el-select
                  size="mini"
                  v-model="basicData.model.areaId.key"
                  placeholder="选择"
                  @change="clickOrgTree"
                >
                  <el-option
                    v-for="(item, index) in orgTree"
                    :key="index"
                    :label="item.label"
                    :value="item.id"
                  />
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="所属医院:" prop="hospitalId.key">
                <el-select
                  size="mini"
                  v-model="basicData.model.hospitalId.key"
                  placeholder="选择"
                  @change="clickOrgTreeC"
                >
                  <el-option
                    v-for="(item, index) in orgTreeC"
                    :key="index"
                    :label="item.label"
                    :value="item.id"
                  />
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="所属部门:" prop="departId.key">
                <el-select size="mini" v-model="basicData.model.departId.key" placeholder="选择">
                  <el-option
                    v-for="(item, index) in orgTreeCs"
                    :key="index"
                    :label="item.label"
                    :value="item.id"
                  />
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="6"></el-col>
          </el-row>
          <el-row>
            <el-col :span="6">
              <el-form-item label="母亲姓名:">
                <el-input size="mini" v-model="basicData.model.momName" placeholder="输入" />
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="性别:">
                <el-select v-model="basicData.model.babySex.key">
                  <el-option
                    :label="item"
                    :value="key"
                    v-for="(item, key, index) in dicts.BABY_SEX"
                  />
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="实验项目:" prop="experimentCode.key">
                <el-select
                  size="mini"
                  v-model="basicData.model.experimentCode.key"
                  @change="chanageExperCode"
                >
                  <el-option
                    v-for="(item, key, index) in dicts.EXPERIMENT_CODE"
                    :key="index"
                    :label="item"
                    :value="key"
                  />
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12" style="display:flex;padding-left: 1.7vw;">
              <el-form-item>
                <el-select
                  style="width:96px !important"
                  size="mini"
                  v-model="codeType"
                  placeholder="实验编号"
                >
                  <el-option
                    v-for="(item, key, index) in dicts.NUMBER"
                    :key="index"
                    :label="item"
                    :value="key"
                  />
                </el-select>
              </el-form-item>
              <div style="display:flex;align-items: center;width:100%">
                <el-form-item style="width:50%">
                  <el-input
                    size="mini"
                    v-model="codeList.start"
                    placeholder="输入"
                    style="width:100%"
                  />
                </el-form-item>
                <span style="margin: 0 17px">至</span>
                <el-form-item style="width:50%">
                  <el-input size="mini" v-model="codeList.end" placeholder="输入" style="width:100%" />
                </el-form-item>
              </div>
            </el-col>
            <el-col :span="6">
              <el-form-item label="审核状态:">
                <el-checkbox-group v-model="checkStatus" @change="chanageCheckStatus">
                  <el-checkbox label="Y">已审核</el-checkbox>
                </el-checkbox-group>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12" style="display:flex;padding-left: 1.7vw;" class="time-list">
              <el-form-item style="width:100%">
                <el-select
                  size="mini"
                  style="width:130px !important"
                  v-model="timeType"
                  placeholder="出生日期"
                >
                  <el-option
                    v-for="(item, key, index) in dicts.TIME"
                    :key="index"
                    :label="item"
                    :value="key"
                  />
                </el-select>
                <el-date-picker
                  size="mini"
                  v-model="timeList"
                  type="daterange"
                  value-format="yyyy-MM-dd"
                  style="width:100%"
                  range-separator="至"
                  start-placeholder="开始日期"
                  end-placeholder="结束日期"
                />
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="筛查结果:">
                <el-select v-model="basicData.model.hint">
                  <el-option :label="item" :value="item" v-for="(item, key, index) in hintList" />
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="实验指标:">
                <el-select v-model="basicData.model.indicatorCode">
                  <el-option
                    :label="item"
                    :value="key"
                    v-for="(item, key, index) in indicatorCodeList"
                  />
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
        </el-row>
      </el-form>
      <div class="buttom" style="margin-top:15px">
        <el-button type="primary" size="small" style="width:100px" @click="onSubmit('query')">查询</el-button>
        <el-button size="small" @click="onSubmit('reset')">清空</el-button>
      </div>
    </el-card>

    <el-card class="box-card" style="margin:5px 15px;">
      <div style="margin-bottom:10px">
        <el-button size="small" type="primary" icon="el-icon-tickets" @click="clickNew">重新编号</el-button>
      </div>
      <el-table
        v-loading="loading"
        :data="tableData"
        style="width: 100%;padding:5px;"
        :header-cell-style="{
          background: '#333333',
          color: '#ffffff',
          textAlign: 'center'
        }"
        @selection-change="selectChanage"
      >
        <el-table-column align="center" type="selection" width="45" />
        <el-table-column align="center" prop="expNum" label="实验编号" width="150" />
        <el-table-column align="center" prop="momName" label="母亲姓名" />
        <el-table-column align="center" prop="bloodTime" label="采血日期">
          <template slot-scope="scope">
            <span>
              {{
              scope.row.bloodTime ? scope.row.bloodTime.substr(0, 10) : ""
              }}
            </span>
          </template>
        </el-table-column>
        <el-table-column align="center" prop="barCode" label="条形码号" width="150" />
        <el-table-column align="center" prop="babySex.data" label="性别" />
        <el-table-column align="center" prop="birthTime" label="出生日期">
          <template slot-scope="scope">
            <span>
              {{
              scope.row.birthTime ? scope.row.birthTime.substr(0, 10) : ""
              }}
            </span>
          </template>
        </el-table-column>
        <el-table-column align="center" prop="receiveMan" label="验收人员" />
        <el-table-column align="center" prop="receiveTime" label="验收日期">
          <template slot-scope="scope">
            <span>
              {{
              scope.row.receiveTime ? scope.row.receiveTime.substr(0, 10) : ""
              }}
            </span>
          </template>
        </el-table-column>
        <el-table-column align="center" prop="barCode" label="条形码号" width="150" />
        <el-table-column align="center" prop="birthTime" label="出生日期">
          <template slot-scope="scope">
            <span>
              {{
              scope.row.birthTime ? scope.row.birthTime.substr(0, 10) : ""
              }}
            </span>
          </template>
        </el-table-column>
        <el-table-column
          align="center"
          prop="sumExperimentValueResult"
          label="实验结果值"
          show-overflow-tooltip
        />
        <el-table-column align="center" label="操作" width="200">
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="primary"
              style="background:#2669F3"
              @click="clickDetails(scope.row)"
            >详情</el-button>
            <el-button
              size="mini"
              type="primary"
              style="background:#2669F3"
              @click="clickSeeReport(scope.row)"
            >报告</el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        :current-page="basicData.current"
        :page-size="basicData.size"
        :total="total"
        layout="slot, total, sizes, prev, pager, next, jumper"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      >
        <span
          v-if="selectList.length > 0"
          style="font-weight: 400;color:#606266"
        >已选中{{ selectList.length }}条，</span>
      </el-pagination>
    </el-card>
    <!-- 重新编号 -->
    <el-dialog
      :visible.sync="newShow"
      :close-on-press-escape="false"
      :close-on-click-modal="false"
      width="80%"
      title="重新编号"
    >
      <el-table
        :data="newTable"
        style="width: 100%;padding:5px;"
        :header-cell-style="{
          background: '#333333',
          color: '#ffffff',
          textAlign: 'center'
        }"
      >
        <el-table-column align="center" type="index" width="45" />
        <el-table-column align="center" prop="newExpNum" label="新实验编号">
          <template slot-scope="scope">
            <el-input v-model="newExpNumList[scope.$index]" size="mini" />
          </template>
        </el-table-column>
        <el-table-column align="center" prop="expNum" label="实验编号" width="150" />
        <el-table-column align="center" prop="receiveMan" label="验收人员" />
        <el-table-column align="center" prop="momName" label="母亲姓名" />
        <el-table-column align="center" prop="birthTime" label="出生日期">
          <template slot-scope="scope">
            <span>
              {{
              scope.row.birthTime ? scope.row.birthTime.substr(0, 10) : ""
              }}
            </span>
          </template>
        </el-table-column>
        <el-table-column align="center" prop="bloodTime" label="采血日期">
          <template slot-scope="scope">
            <span>
              {{
              scope.row.bloodTime ? scope.row.bloodTime.substr(0, 10) : ""
              }}
            </span>
          </template>
        </el-table-column>
        <el-table-column align="center" prop="receiveTime" label="验收日期">
          <template slot-scope="scope">
            <span>
              {{
              scope.row.receiveTime ? scope.row.receiveTime.substr(0, 10) : ""
              }}
            </span>
          </template>
        </el-table-column>
      </el-table>

      <div class="flex" style="margin-top:40px">
        <el-button
          type="mini"
          style="background:#2669F3;width:120px;color:#fff"
          @click="clickSeave"
        >保存</el-button>
      </div>
    </el-dialog>

    <!-- 详情 -->
    <el-dialog width="65%" title="实验数据" :visible.sync="detailsShow" append-to-body>
      <el-tabs v-model="activeName" @tab-click="handleClick" stretch>
        <el-tab-pane
          :label="item.experimentCode.data"
          :name="item.experimentCode.key"
          v-for="(item,index) in  detailsData"
        >
          <!-- 表格 -->
          <el-row style="line-height: 1.5;border:1px solid">
            <el-col
              :span="5"
              style="display:flex;justify-content: center;color:#000000f2;font-size: 15px;border-right:1px solid"
            >筛查项目</el-col>
            <el-col
              :span="3"
              style="display:flex;justify-content: center;color:#000000f2;font-size: 15px;border-right:1px solid"
            >检测指标</el-col>
            <el-col
              :span="3"
              style="display:flex;justify-content: center;color:#000000f2;font-size: 15px;border-right:1px solid"
            >检测值</el-col>
            <el-col
              :span="5"
              style="display:flex;justify-content: center;color:#000000f2;font-size: 15px;border-right:1px solid"
            >正常参考值</el-col>
            <el-col
              :span="8"
              style="display:flex;justify-content: center;color:#000000f2;font-size: 15px;"
            >筛查结果</el-col>
            <!-- hint -->
          </el-row>
          <!-- 表格内容 -->
          <el-row
            style="line-height: 1.5;border-bottom:1px solid;border-left:1px solid;border-right:1px solid;"
          >
            <div v-for="(items, key, indexs) in item.experimentValue" :key="indexs">
              <el-col
                :span="5"
                :style="items.experimentValueResult != 'normal' ? 'background-color:#baccef;':''"
                style="display:flex;justify-content: center;color:#000000f2;font-size: 15px;border-right:1px solid"
              >{{ items.indicatorCodeName }}&nbsp</el-col>
              <el-col
                :span="3"
                :style="items.experimentValueResult != 'normal' ? 'background-color:#baccef;':''"
                style="display:flex;justify-content: center;color:#000000f2;font-size: 15px;border-right:1px solid"
              >{{ items.indicatorCode }}&nbsp</el-col>
              <el-col
                :span="3"
                :style="items.experimentValueResult != 'normal' ? 'background-color:#baccef;':''"
                style="display:flex;justify-content: center;color:#000000f2;font-size: 15px;border-right:1px solid"
              >{{ items.experimentValue }}{{ items.units }}&nbsp</el-col>
              <el-col
                :span="5"
                :style="items.experimentValueResult != 'normal' ? 'background-color:#baccef;':''"
                style="display:flex;justify-content: center;color:#000000f2;font-size: 15px;border-right:1px solid"
              >{{ items.referenceValue }}&nbsp</el-col>
              <el-col
                :span="8"
                :style="items.experimentValueResult != 'normal' ? 'background-color:#baccef;':''"
                style="display:flex;justify-content: center;color:#000000f2;font-size: 15px;border-right:1px solid"
              >{{ items.hint }}&nbsp</el-col>
            </div>
          </el-row>
        </el-tab-pane>
      </el-tabs>
    </el-dialog>

    <!-- 报告 -->
    <el-dialog width="85%" title="实验数据" :visible.sync="viewReportShow" append-to-body>
      <span slot="title" class="dialog-title" style="font-size: 18px;font-weight: 400;color:#fff">报告</span>
      <el-tabs v-model="activeName" @tab-click="handleClick" stretch>
        <el-tab-pane
          :label="item.experimentCodeName"
          :name="item.experimentCode"
          v-for="(item,index) in  viewReportData"
        >
          <!-- 传统 -->
          <chuantong
            :dataList="[viewReportData['PHE+TSH+17_a_OHP+G6PD']]"
            v-if="item.experimentCode == 'PHE+TSH+17_a_OHP+G6PD'"
          ></chuantong>
          <!-- 串联 -->
          <chuanlian :dataList="[viewReportData['MSMS']]" v-if="item.experimentCode == 'MSMS'"></chuanlian>
          <!-- 地贫 -->
          <diping :dataList="[viewReportData['THA']]" v-if="item.experimentCode == 'THA'"></diping>
          <!-- 耳聋基因 -->
          <erlongjiyin :dataList="[viewReportData['DGT']]" v-if="item.experimentCode == 'DGT'"></erlongjiyin>
        </el-tab-pane>
      </el-tabs>
      <span slot="footer" class="dialog-footer" style="display:flex;justify-content: center;">
        <el-button v-print="'#print'" size="small" type="primary" style="padding: 6px 19px;">打 印</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import DeliveryManageApi from "@/api/DeliveryManage.js";
import { initDicts } from "@/utils/commons";
import orgApi from "@/api/Org.js";
import diping from "./diping.vue";
import chuantong from "./chuantong.vue";
import chuanlian from "./chuanlian.vue";
import erlongjiyin from "./erlongjiyin.vue";

export default {
  components: {
    diping,
    chuantong,
    chuanlian,
    erlongjiyin
  },
  data() {
    return {
      // 转菊花
      loading: false,
      // 是否展示更多信息
      morderShow: true,
      // 重新编号显示
      newShow: false,
      total: 0,
      // 表格数据
      tableData: [],
      // 选中数据
      selectList: [],
      newTable: [],
      dateList: [],
      //时间类型
      timeType: "",
      //编码类型
      codeType: "",
      //时间列表
      timeList: [],
      // 编码
      codeList: {
        start: "",
        end: ""
      },
      // 基本数据
      basicData: {
        current: 1,
        map: {},
        model: {
          areaId: {
            key: ""
          },
          babySex: {
            data: "",
            key: ""
          },
          barCode: {
            end: "",
            start: ""
          },
          birthTime: {
            end: "",
            start: ""
          },
          bloodNum: {
            end: "",
            start: ""
          },
          bloodTime: {
            end: "",
            start: ""
          },
          createTime: {
            end: "",
            start: ""
          },
          departId: {
            key: ""
          },
          expNum: {
            end: "",
            start: ""
          },
          experimentCheckStatus: "N",
          experimentCode: {
            data: "",
            key: "THA"
          },
          experimentTime: {
            end: "",
            start: ""
          },
          freeNum: {
            end: "",
            start: ""
          },
          hint: "",
          hospitalId: {
            key: ""
          },
          indicatorCode: "",
          momName: "",
          reportTime: {
            end: "",
            start: ""
          }
        },
        order: "descending",
        size: 10,
        sort: "id"
      },
      // 校验
      basicDataRules: {
        countyAndCitiesId: [
          { required: false, message: "  ", trigger: "change" }
        ],
        "experimentCode.key": [
          { required: true, message: "  ", trigger: "change" }
        ],
        hospitalId: [{ required: false, message: "  ", trigger: "change" }],
        deptId: [{ required: false, message: "  ", trigger: "change" }]
      },
      // 新变化list
      newExpNumList: [],
      // 市县
      orgTree: [],
      // 医院
      orgTreeC: [],
      // 部门
      orgTreeCs: [],
      // 字典
      dicts: {
        MOM_CENSUS: {}, //母亲户籍
        BABY_SEX: {}, //婴儿性别
        FLOW_STATUS: {}, //流程状态
        TIME: {}, //时间
        NUMBER: {}, //编码
        EXPERIMENT_CODE: {} //实验项目
      },
      checkStatus: false,
      hintList: [],
      indicatorCodeList: [],
      detailsData: [],
      detailsShow: false,
      activeName: "THA",
      viewReportData: [],
      viewReportShow: false
    };
  },
  mounted() {
    // 获取字典
    initDicts(
      [
        "MOM_CENSUS",
        "BABY_SEX",
        "FLOW_STATUS",
        "TIME",
        "NUMBER",
        "EXPERIMENT_CODE"
      ],
      this.dicts
    );
    this.getList(this.basicData);
    this.initOrgTree();
    this.chanageExperCode();
  },
  methods: {
    handleClick(tab, event) {},
    // 点击详情
    clickDetails(row) {
      let data = {
        expNum: row.expNum
      };
      DeliveryManageApi.sampleQuery.viewResult(data).then(res => {
        if (res.data.data) {
          for (let key in res.data.data) {
            let sortDatas = [];
            for (let keys in res.data.data[key].experimentValue) {
              sortDatas.push(res.data.data[key].experimentValue[keys]);
            }
            res.data.data[key].experimentValue = this.$keysrt(
              sortDatas,
              "sortValue"
            );
          }
          this.detailsData = res.data.data;
          this.detailsShow = true;
        }
      });
    },
    // 点击报告
    clickSeeReport(row) {
      let data = {
        expNum: row.expNum
      };
      DeliveryManageApi.sampleQuery.viewReport(data).then(res => {
        if (res.data.data) {
          for (let key in res.data.data) {
            let sortDatas = [];
            for (let keys in res.data.data[key].experimentValue) {
              sortDatas.push(res.data.data[key].experimentValue[keys]);
            }
            res.data.data[key].experimentValue = this.$keysrt(
              sortDatas,
              "sortValue"
            );
          }
          this.viewReportData = res.data.data;
          this.viewReportShow = true;
        }
      });
    },
    // 实验项目变化
    chanageExperCode(v) {
      DeliveryManageApi.sampleQuery.hintList({ code: v || "THA" }).then(res => {
        this.hintList = res.data.data;
      });
      DeliveryManageApi.sampleQuery
        .indicatorList({ code: v || "THA" })
        .then(res => {
          this.indicatorCodeList = res.data.data;
        });
    },
    // 已审核点击
    chanageCheckStatus(v) {
      if (v) {
        this.basicData.model.experimentCheckStatus = "Y";
      } else {
        this.basicData.model.experimentCheckStatus = "N";
      }
    },
    // 实验日期变动时候调用
    timeChange(v) {
      if (v && v.length > 0) {
        this.basicData.model.experimentDate.start = v[0];
        this.basicData.model.experimentDate.end = v[1];
      } else {
        this.basicData.model.experimentDate = {
          end: "",
          start: ""
        };
      }
    },
    // 获取基础查询
    initOrgTree() {
      orgApi.allTree({}).then(response => {
        const res = response.data;
        this.orgTree = res.data[0].children;
      });
    },
    // 根据选择市县获取医院
    clickOrgTree(v) {
      this.orgTreeC = [];
      this.orgTreeCs = [];
      this.basicData.hospitalId.key = "";
      this.basicData.departId.key = "";
      this.orgTree.filter(res => {
        if (res.id == v) {
          this.orgTreeC = res.children;
        }
      });
    },
    // 根据选择市县获取医院
    clickOrgTreeC(v) {
      this.orgTreeCs = [];
      this.basicData.departId.key = "";
      this.orgTreeC.filter(res => {
        if (res.id == v) {
          this.orgTreeCs = res.children;
        }
      });
    },
    // 操作按钮
    onSubmit(type) {
      if (type == "query") {
        this.$refs["basicForm"].validate(valid => {
          if (valid) {
            switch (this.timeType) {
              // 实验日期"
              case "experimenttime":
              case "":
                this.basicData.model.experimentTime = {
                  start: this.timeList[0],
                  end: this.timeList[1]
                };
                this.basicData.model.birthTime = {
                  start: "",
                  end: ""
                };
                this.basicData.model.bloodTime = {
                  start: "",
                  end: ""
                };
                this.basicData.model.createTime = {
                  start: "",
                  end: ""
                };
                this.basicData.model.reportTime = {
                  start: "",
                  end: ""
                };
                break;
              // 采血日期
              case "bloodtime":
                this.basicData.model.bloodTime = {
                  start: this.timeList[0],
                  end: this.timeList[1]
                };
                this.basicData.model.birthTime = {
                  start: "",
                  end: ""
                };
                this.basicData.model.createTime = {
                  start: "",
                  end: ""
                };
                this.basicData.model.experimentTime = {
                  start: "",
                  end: ""
                };
                this.basicData.model.reportTime = {
                  start: "",
                  end: ""
                };
                break;
              // 登记日期
              case "createtime":
                this.basicData.model.createTime = {
                  start: this.timeList[0],
                  end: this.timeList[1]
                };
                this.basicData.model.birthTime = {
                  start: "",
                  end: ""
                };
                this.basicData.model.bloodTime = {
                  start: "",
                  end: ""
                };
                this.basicData.model.experimentTime = {
                  start: "",
                  end: ""
                };
                this.basicData.model.reportTime = {
                  start: "",
                  end: ""
                };
                break;
              // 出生日期
              case "birthtime":
                this.basicData.model.birthTime = {
                  start: this.timeList[0],
                  end: this.timeList[1]
                };
                this.basicData.model.bloodTime = {
                  start: "",
                  end: ""
                };
                this.basicData.model.createTime = {
                  start: "",
                  end: ""
                };
                this.basicData.model.experimentTime = {
                  start: "",
                  end: ""
                };
                this.basicData.model.reportTime = {
                  start: "",
                  end: ""
                };
                break;
              // 报告日期
              case "reporttime":
                this.basicData.model.reportTime = {
                  start: this.timeList[0],
                  end: this.timeList[1]
                };
                this.basicData.model.birthTime = {
                  start: "",
                  end: ""
                };
                this.basicData.model.bloodTime = {
                  start: "",
                  end: ""
                };
                this.basicData.model.createTime = {
                  start: "",
                  end: ""
                };
                this.basicData.model.experimentTime = {
                  start: "",
                  end: ""
                };
                break;
            }
            switch (this.codeType) {
              // 实验编号"
              case "expnum":
              case "":
                this.basicData.model.expNum = {
                  start: this.codeList.start,
                  end: this.codeList.end
                };
                this.basicData.model.bloodNum = {
                  start: "",
                  end: ""
                };
                this.basicData.model.barCode = {
                  start: "",
                  end: ""
                };
                this.basicData.model.freeNum = {
                  start: "",
                  end: ""
                };

                break;
              // 采血编号
              case "bloodnum":
                this.basicData.model.barCode = {
                  start: this.codeList.start,
                  end: this.codeList.end
                };
                this.basicData.model.bloodNum = {
                  start: "",
                  end: ""
                };
                this.basicData.model.expNum = {
                  start: "",
                  end: ""
                };
                this.basicData.model.freeNum = {
                  start: "",
                  end: ""
                };
                break;
              // 条形码号
              case "barcode":
                this.basicData.model.barCode = {
                  start: this.codeList.start,
                  end: this.codeList.end
                };
                this.basicData.model.bloodNum = {
                  start: "",
                  end: ""
                };
                this.basicData.model.expNum = {
                  start: "",
                  end: ""
                };
                this.basicData.model.freeNum = {
                  start: "",
                  end: ""
                };
                break;
              // 免费券号
              case "freenum":
                this.basicData.model.freeNum = {
                  start: this.codeList.start,
                  end: this.codeList.end
                };
                this.basicData.model.bloodNum = {
                  start: "",
                  end: ""
                };
                this.basicData.model.expNum = {
                  start: "",
                  end: ""
                };
                this.basicData.model.barCode = {
                  start: "",
                  end: ""
                };
                break;
            }
            this.getList(this.basicData);
          } else {
            return false;
          }
        });
      } else if (type == "reset") {
        this.checkStatus = false;
        this.basicData.model = {
          areaId: {
            key: ""
          },
          babySex: {
            data: "",
            key: ""
          },
          barCode: {
            end: "",
            start: ""
          },
          birthTime: {
            end: "",
            start: ""
          },
          bloodNum: {
            end: "",
            start: ""
          },
          bloodTime: {
            end: "",
            start: ""
          },
          createTime: {
            end: "",
            start: ""
          },
          departId: {
            key: ""
          },
          expNum: {
            end: "",
            start: ""
          },
          experimentCheckStatus: "N",
          experimentCode: {
            data: "",
            key: "THA"
          },
          experimentTime: {
            end: "",
            start: ""
          },
          freeNum: {
            end: "",
            start: ""
          },
          hint: "",
          hospitalId: {
            key: ""
          },
          indicatorCode: "",
          momName: "",
          reportTime: {
            end: "",
            start: ""
          }
        };
        this.timeType = "";
        this.codeType = "";
        this.timeList = [];
        this.codeList = {
          start: "",
          end: ""
        };
        this.getList(this.basicData);
        this.$refs["basicForm"].resetFields();
      }
    },
    // 从新编号保存
    clickSeave() {
      let data = [];
      this.newTable.forEach((item, index) => {
        data[index] = {
          barCode: item.barCode,
          expNum: item.expNum,
          id: item.id,
          newExpNum: this.newExpNumList[index]
        };
      });
      DeliveryManageApi.sampleQuery
        .updExpNum(data)
        .then(res => {
          if (res.status == 200) {
            this.$message({
              message: res.statusText,
              type: "success"
            });
            this.getList(this.basicData);
          } else {
            this.$message.error(res.statusText);
          }
        })
        .finally(() => {
          this.newShow = false;
        });
    },
    // 重新编号
    clickNew() {
      if (this.selectList.length == 0) {
        this.$message.error("请选择数据");
        return;
      }
      let ids = [];
      this.selectList.forEach(item => {
        ids.push(item.id);
      });
      DeliveryManageApi.sampleQuery.sampleList(ids).then(res => {
        this.total = res.data.data.total;
        this.newTable = res.data.data;
        res.data.data.forEach((item, index) => {
          this.newExpNumList[index] = "";
        });
        this.newShow = true;
      });
    },
    // 选中数据
    selectChanage(v) {
      this.selectList = v;
    },
    // 获取数据
    getList(data) {
      this.loading = true;
      DeliveryManageApi.sampleQuery
        .page(data)
        .then(res => {
          if (res.status == 200) {
            this.tableData = res.data.data.records;
            this.total = res.data.data.total;
          } else {
            this.$message.error(res.statusText);
          }
        })
        .finally(() => {
          this.loading = false;
        });
    },
    //点击全选
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    // 点击分页
    handleSizeChange: function(val) {
      this.basicData.size = val;
      this.getList(this.basicData);
    },
    // 选择页码
    handleCurrentChange: function(currentPage) {
      this.basicData.current = currentPage;
      this.getList(this.basicData);
    }
  }
};
</script>

<style lang="less">
.flex {
  display: flex;
  align-items: center;
  justify-content: center;
}
#sampleQuerysss {
  .el-form-item__content,
  .el-date-editor,
  .el-select,
  .el-textarea {
    width: 100% !important;
  }
  .el-range-separator {
    width: 10%;
  }
  .el-form-item__content,
  .el-date-editor,
  .el-select,
  .el-textarea {
    width: 100% !important;
  }
  .buttom {
    width: 100%;
    .flex;
  }
  .mores {
    .flex;
    justify-content: flex-start;
    .more-title {
      font-size: 12px;
      font-family: SourceHanSansSC;
      font-weight: 400;
      color: rgb(153, 153, 153);
      font-style: normal;
      letter-spacing: 0px;
      line-height: 20px;
      text-decoration: none;
      margin-right: 1rem;
    }
  }
}
</style>
